	package VNF_DelayTest_large_modified01;

import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import com.net2plan.interfaces.networkDesign.NetPlan;
import com.net2plan.interfaces.networkDesign.Node;

/**
 * 
 * @author shentianyu
 *
 *此版本对请求排序的规则：请求所需的cpu数量从多到少排序
 *
 */
public class Main {
	
	//存放请求的集合
	//排序前的所有请求
	static List<NetPlan> allRequestList = new ArrayList<NetPlan>();
	static List<NetPlan> requestList = new ArrayList<NetPlan>();
	static List<NetPlan> requestGroup = new ArrayList<NetPlan>();
	private static final int numberOfAllRequests = 200;
	private static final int numberOfRequests = 200;
	public static int numberOfAllVNFTypes = 8;
	public static int numberOfAllSlot = 300 ;
	public static int numberOfCPU = 50;
	public static int numberOfDC = 14;
	static List<Integer> mfsiList = new ArrayList<Integer>();
	static List<Double> averageCostList = new ArrayList<Double>();
	static List<Integer> totalUsedCPUList = new ArrayList<Integer>();
	static List<Double> totalDelayTimeList = new ArrayList<Double>();
	static List<Double> blockList = new ArrayList<Double>();

	public static void main(String[] args) {
		//生成请求
		for(int i=0;i<numberOfAllRequests;i++) {
			NetPlan request = CreateNetPlan.createOneNetplan();
			allRequestList.add(request);
		}
		String ch = new String() ;
		ch = "/Users/shentianyu/Net2Plan-0.4.0/workspace/data/networkTopologies/US_Backbone.n2p";
		File f1 = new File(ch);
		NetPlan subNetPlan = new NetPlan(f1);
		List<Node> subNodes = subNetPlan.getNodes();
		//对请求进行铺设
		for(int k = 0;k<numberOfAllRequests; k++) {

			if(k%numberOfRequests==0) {
				//对所有的设置进行初始化
				requestList.clear();
				InitialNetPlan.initialNetplan();
			}
			requestList.add(allRequestList.get(k));
			if(k%numberOfRequests==numberOfRequests-1) {
				//根据资源需求量的多少对请求集合进行排序(降序)
				Collections.sort(requestList, (a,b)->Integer.valueOf(b.getAttribute("resource")).compareTo(Integer.valueOf(a.getAttribute("resource"))));
//				for(NetPlan request:requestList) {
//					System.out.println(request.getAttribute("resource"));
//				}
				//对请求进行节点映射,节点映射完成后立刻进行链路映射
				//所以链路映射方法在节点映射方法内调用
				MyUtil.nodeMapping(subNetPlan, requestList);
				for(Node node:subNodes) {
					if("1".equals(node.getAttribute("DataCenter"))) {
					System.out.println(" 数据中心"+subNodes.indexOf(node));
					for(int vnfType = 1;vnfType<=numberOfAllVNFTypes;vnfType++) {
						System.out.print(" VNF"+vnfType+": "+node.getAttribute(String.valueOf(vnfType))+",  ");
//						int vnfNum = Integer.valueOf(node.getAttribute(String.valueOf(vnfType))).intValue();
//						if(vnfNum>0) {
//							totalusedcpu+=vnfType;
//						}
					}
					System.out.println();
				}
			}
				System.out.println("阻塞的请求数"+subNetPlan.getAttribute("BlockedRequest"));
			}
		}
	}
}
